package com.example.administrator.familfinalcialmanagement.ui.fragment;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.databinding.FragmentSecondBinding;
import com.example.administrator.familfinalcialmanagement.ui.adapter.ClassNameLeftAdapter;
import com.example.administrator.familfinalcialmanagement.ui.adapter.ParentClassNameRightAdapter;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;
import com.example.administrator.familfinalcialmanagement.util.listener.OnChildListener;
import com.example.administrator.familfinalcialmanagement.util.listener.OnItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/3/27.
 */

public class SecondFragment extends BaseLazyFragment {

    FragmentSecondBinding binding;

    List<String> leftStrs = new ArrayList<>();
    List<TextView> tvs = new ArrayList<>();
    ClassNameLeftAdapter leftAdapter;

    ParentClassNameRightAdapter rightAdapter;

    @Override
    protected View inflaterView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(LayoutInflater.from(getActivity()), R.layout.fragment_second, container, false);
        binding.setFragment(this);
        return binding.getRoot();
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        leftStrs.clear();
        leftStrs.add("小学");
        leftStrs.add("初中");
        leftStrs.add("艺术类");
        leftStrs.add("体育");
        leftStrs.add("生活兴趣");
        leftAdapter = new ClassNameLeftAdapter(getActivity(),leftStrs);
        binding.recyclerLeft.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.recyclerLeft.setItemAnimator(new DefaultItemAnimator());
        binding.recyclerLeft.setAdapter(leftAdapter);
        tvs = leftAdapter.tvs;
        leftAdapter.setOnItemClickLitener(new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                for(TextView tv : tvs){
                    tv.setTextColor(getActivity().getResources().getColor(R.color.white));
                    tv.setBackgroundColor(getActivity().getResources().getColor(R.color.ff862e));
                }
                tvs.get(position).setTextColor(getActivity().getResources().getColor(R.color.tv_1));
                tvs.get(position).setBackgroundColor(getActivity().getResources().getColor(R.color.F0F0F0));

            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });

        binding.recyclerRight.setLayoutManager(new LinearLayoutManager(getActivity()));
        binding.recyclerRight.setItemAnimator(new DefaultItemAnimator());
        rightAdapter = new ParentClassNameRightAdapter(getActivity(),leftStrs);
        binding.recyclerRight.setAdapter(rightAdapter);
        rightAdapter.setOnChildListener(new OnChildListener() {
            @Override
            public void onChildListener(int position, int ChildPosition) {
                ToastUtil.showToast("点击"+ leftStrs.get(position) + "的第"+ ChildPosition + "个科目");
            }
        });


        /**
         * 两个view的滑动监听
         */
        binding.recyclerLeft.addOnScrollListener( new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged( recyclerView, newState );

            }
        } );

    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void lazyLoad() {
    }

    @Override
    public int setLayoutId() {
        return R.layout.fragment_second;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            default:
        }
    }
}